home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / nos_kit3.zip / UUDECODE.DOC < prev    next >
Text File  |  1990-03-01  |  11KB  |  242 lines

  1.  
  2. UU-encoding is a way to code a file which may contain any characters into
  3. a standard character set that can be reliably sent over diverse networks.
  4.  
  5.  
  6. THE CHARACTER ENCODING:
  7.  
  8. The basic scheme is to break groups of 3 eight bit characters (24 bits) into
  9. 4 six bit characters and then add 32 (a space) to each six bit character
  10. which maps it into the readily transmittable character.  Another way of
  11. phrasing this is to say that the encoded 6 bit characters are mapped into
  12. the set:
  13.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  14. for transmission over communications lines.
  15.  
  16. As some transmission mechanisms compress or remove spaces, spaces are changed
  17. into back-quote characters (a 96).  (A better scheme might be to use a bias
  18. of 33 so the space is not created, but this is not done.)
  19.  
  20. Another newer less popular encoding method, called XX-encoding uses the set:
  21.         +-01..89ABC...XYZabc...xyz
  22.  
  23. In my opinion, XX-encoding is superior to UU-encoding because it uses more
  24. "normal" characters that are less likely to get corrupted.  In fact several
  25. of the special characters in the UU set do not get thru an EBCDIC to ASCII
  26. translation correctly.  Conversely, an advantage of the UU set is that it does
  27. not use lower case characters.  Now-a-days both upper and lower case are sent
  28. with no problems; maybe in the communications dark ages, there was a problem
  29. with lower case.
  30.  
  31. This "UU" encode/decode pair can handle either XX or UU encoding.  The encode
  32. program defaults to creating a UU encoded file; but can be run with a "-x"
  33. option to create an XX encoding.
  34.  
  35. The decode program defaults to autodetect.  However the program can get
  36. confused by comment lines preceeding the actual encoded data.  The decode
  37. mode can be forced to UU or XX with the "-u" or "-x" parameter.
  38.  
  39. Another option is for the actual map table to be inserted at the front of the
  40. file.  The format for this is discussed later.  The table parameters are
  41. detected and used by this decode program.  (A table will override the "-x" or
  42. "-u" parameters.)  The encode program can be run with a "-t" option which
  43. tells it to put the table into the encoded file.
  44.  
  45. A third encode mapping is the one used by Brad Templeton's ABE program.  This
  46. is not handled by these programs as the check and control information
  47. surrounding the actual encoded data is in a different form.
  48.  
  49.  
  50. COMPOSING A LINE OF ENCODED CHARACTERS:
  51.  
  52. A small number of eight bit characters are encoded into a single line and a
  53. count is put at the start of the line.  (Most lines in an encoded file have 45
  54. encoded characters.  When you look at a UU-encoded file note that most lines
  55. start with the letter "M".  "M" is decimal 77 which, minus the 32 bias, is 45.)
  56.  
  57. This encode program puts a check character at the end of each line.  The check
  58. is the sum of all the encoded characters, before adding the mapping, modulo 64.
  59.  
  60. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it uses the
  61. sum of the original, not the encoded characters.  This decode program accepts
  62. either form of line check character.
  63.  
  64. The line check characters are generated by default by this encode program.
  65. However they can be supressed with the "-L" option.  One reason to supress
  66. them is if they will be decoded by one of the old Horton decoders.  Most
  67. decoders either accept this form of check or simply stop looking after the
  68. line length is exhausted.  My feelings are mixed about the line level check
  69. because errors of this type essentially never occur.  Furthermore file errors
  70. will be detected by the CRC checks on the entire file (see below).
  71. Opinions solicited.
  72.  
  73. The decode program checks the line level checksum by default.  Sometimes there
  74. is junk at the end of the line which causes spurious line checksum errors.
  75. To suppress checking of line checksums when decoding, use the "-L" option.
  76.  
  77. I have encountered various other ways that encoders end lines.  One encoder
  78. put a "M" at both the start and end of the line.  Another used a line count
  79. character.  This decode program checks all of these.  I would not be surprised
  80. if some encoder out there ends lines with astrological symbols.  If you
  81. encounter some other wierd form of encoded file, let me know.
  82.  
  83.  
  84. PACKAGING THE LINES INTO FILES:
  85.  
  86. The lines of encoded data can be preceded by comments and by network addressing
  87. information.  The encoded data is directly preceded by a line containing:
  88.  
  89.              begin <file-mode> <file-name>
  90.  
  91. This line is created by the encoding program.  The decode program scans the
  92. file looking for "begin" in column 1.
  93.  
  94. The final end of encoded data is an encoded line with zero encoded characters
  95. (two back-quotes), followed by a line containing "end".
  96.  
  97. For integrity checking, various encode programs insert checksums for the
  98. entire file.  This decode tries to check for all known types of file checksums.
  99. This is discussed in more detail later.
  100.  
  101. This encode program puts a header line, containing the section number and
  102. file name, in front of every section:
  103.  
  104.          "section <number> of uuencode of file <file name>"
  105.  
  106. At the end of a section the encode program inserts a line containing checksum
  107. and file size information.  This can be suppressed with the "-c" option.
  108.  
  109. All the "integrity fields" (the checksum, the line check, and the section
  110. header line) are inserted in a way that they will be ignored by other UUDECODE
  111. programs that cannot handle them.  This decode program does not require any of
  112. these fields; if not present, integrity checking is not done.  This program
  113. pair is 100% downward compatible!
  114.  
  115.  
  116. SPLITING UP LONG FILES:
  117.  
  118. Long files are broken into several sections before transmission.  This is
  119. done because very large files are cumbersome to handle and because some
  120. networks require files to be less than 64K bytes.
  121.  
  122. This encode program automatically breaks large encoded files into sections.
  123. This split is controlled by several options.  First the "-s" option tells
  124. encode not to split the file.  The "-s nnn" option tells encode to split the
  125. file into hunks of "nnn" lines.  The default is 950 lines which is about 59k.
  126. Sometimes extensive comments are put into the first file; thus it may be
  127. necessary for the first file to contain fewer encoded lines.  The "-h nnn"
  128. option tells encode to leave room for "nnn" additional lines in the first file.
  129.  
  130. If the data file being encoded is called FOO.ZIP, then the encode program
  131. names the encoded files FOO1.UUE, FOO2.UUE, etc.
  132.  
  133. The decode program searches for the various sections, scans over preliminary
  134. comments and decodes all as if they were one big file.  Decode is passed the
  135. base file name "FOO".
  136.  
  137. Decode can (but rarely does) get confused and thinks header lines are encoded
  138. data.  If so, edit the file and try again.  This has only happened once to me
  139. and I have decoded a lot of files.
  140.  
  141. When decode encounters a premature end-of-file or some data which is not
  142. decodable, it assumes the end of a file section.  decode is conservative when
  143. it encounters data it cannot decode.
  144.  
  145. Usually this undecodable data is valid "trailer" data put at the end of file
  146. for data transmission purposes.  However the file may be bad.  So decode
  147. continues to scan the file, if decode then encounters a line which is decodable
  148. it assumes the file is bad.  Or if there are more than 30 lines remaining in
  149. the file, decode assumes the file is bad.
  150.  
  151. When decode encounters a valid end of file section it must get the next file
  152. in sequence.  If the file name ends with a number, decode tries the next file
  153. name in numeric sequence.  Otherwise decode asks for a file name.  If this
  154. file does not contain decodable data, decode asks for another file to try.
  155.  
  156. The "SECTION" line inserted by the encode program is used for validity checking
  157. only.  If not present, decode will accept any file containing encoded lines.
  158.  
  159.  
  160. OTHER FILE FORMS:
  161.  
  162. Sometimes files come across in shell archives that automatically check
  163. sequencing and call uudecode for you on the UNIX systems.  If you prefer to
  164. download the raw files to MS-DOS, this decode program will filter thru simple
  165. shell scripts and decode the data automatically.
  166.  
  167. There is one more rarely used feature of ENCODE: many input files can be
  168. encoded into one large encode file.  (I have never seen this used.)  The end
  169. of an input file is a zero length encoded line, followed by another "begin"
  170. line instead of by an "end" line.  This decode program will decode this sort of
  171. file; but the encode will only handle a single input file.
  172.  
  173.  
  174. FILE LEVEL CHECKSUMS:
  175.  
  176. There are three types of file checksums found in encoded files:
  177.  
  178.        UUENCODE 2.14 and below inserted lines that gave the section
  179.        size and the original input file size.  This is supplanted
  180.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  181.        and validates the old form
  182.  
  183.        UUENCODE 3.07 and Rahul Dhesi''s encode scripts compute a Unix
  184.        "sum -r" on the encoded sections and on the original input file.
  185.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  186.        and size at the end of a file while Rahul''s scripts put them at
  187.        begining.  This UUDECODE analyzes either.
  188.  
  189.        The third form of checksum is a full 32 bit CRC that Rahul''s script
  190.        inserts.  My code does not handle this.  Rahul has written the
  191.        BRIK program to check them.  If there is a "sum -r" failure, BRIK
  192.        analysis should be considered.
  193.  
  194.  
  195. TABLE LINES:
  196.  
  197. Some encoded files but the mapping used at the front of the encoded file,
  198. just in front of the "begin" line.  The format for this is:
  199.  
  200.                    table
  201.                    first 32 characters
  202.                    second 32 characters
  203.  
  204. All this starts in column 1.
  205.  
  206. If decode encounters a table specification, it uses it and overrides any
  207. command line parameters.  Encode will create the table lines if run with
  208. the "-t" parameter.
  209.  
  210.  
  211. COMPLETION CODES:
  212.  
  213. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are any
  214. problems, ERRORLEVEL is set to non-zero.
  215.  
  216. Most of the options to UUDECODE are obvious.  However, the "-e" option needs
  217. more explanation.  The purpose of "-e" is to automatically run an un-archiver
  218. (like ZOO or PKUNPAK) when UUDECODE successfully completes.  If the "-e"
  219. option is given, UUDECODE calls BAT file UNARCUUE on successful completion
  220. UNARCUUE is passed two parameters:
  221.  
  222.                 the filename decoded (with no extension)
  223.                 the file extension.
  224.  
  225. Normally the file extension tells which un-archiver to call.  The UNARCUUE
  226. BAT file, can test these parameters and call the necessary un-archiver.
  227.  
  228.  
  229. This works well for me.  On UNIX I find a program I want in three sections:
  230.               PRG1, PRG2, PRG3.
  231. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.  I
  232. then just enter UUDECODE PRG and the thing decodes.
  233.  
  234.  
  235. Done privately and not for profit (freeware).  Suggestions appreciated.
  236. The programs are written in Turbo Pascal 5.5 with about 5% TASM for speed.
  237.  
  238.  
  239. Richard Marks
  240. 931 Sulgrave Lane
  241. Bryn Mawr, PA 19010
  242.